<template>
  <div class="dot-wrapper" v-if="hasDot">
    <div class="dot-item" v-for="item in itemLen" :key="item">
      <!-- 设置用户配置的背景颜色 dotBgColor -->
      <!-- item - 1 因为遍历的是item转为index需减1 -->
      <!-- @click="dotClick(item - 1)" 向父组件传入index -->
      <a
        class="dot-lk"
        href="javascript:;"
        :style="{
          backgroundColor: item - 1 === currentIndex ? dotBgColor : '#fff',
        }"
        @click="dotClick(item - 1)"
      ></a>
    </div>
  </div>
</template>

<script>
export default {
  name: "Dot",
  props: {
    itemLen: Number,
    currentIndex: Number,
    hasDot: {
      type: Boolean,
      default: true,
    },
    dotBgColor: {
      type: String,
      default: "#ff5000",
    },
  },
  methods: {
    dotClick(index) {
      this.$emit("dotClick", index);
    },
  },
};
</script>

<style lang="scss" scoped>
.dot-wrapper {
  width: 70px;
  height: 13px;
  border-radius: 10px;
  position: absolute;
  bottom: 15px;
  left: 50%;
  text-align: center;
  font-size: 0;
  z-index: 1;
  margin-left: -39px;
  background-color: rgba(255, 255, 255, 0.3);

  .dot-item {
    display: inline-block;
    margin: 3px;
  }

  .dot-lk {
    display: block;
    padding-top: 8px;
    width: 8px;
    height: 0;
    border-radius: 50%;
    background: #fff;
  }
}
</style>
